package cn.wolfcode.advice;

import cn.wolfcode.exception.LogicException;
import cn.wolfcode.util.JsonResult;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class CommonExceptionHandle {
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object displayExp(LogicException e, Model model){
        e.printStackTrace();
        return JsonResult.error(JsonResult.CODE_ERROR, e.getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object  runTimeExp(Exception e){
        e.printStackTrace();
        return JsonResult.defaultError();
    }
}
